/**
 * 
 */
package com.android.weibogo;

import java.util.ArrayList;

import android.os.Parcel;
import android.os.Parcelable;

import com.mime.qweibo.utils.QWeiboType.InfoType;

/**
 * @author xiang.jianhua
 *
 */
public class TecentWeiboInfo extends WeiboInfo implements Parcelable{
	private TecentWeiboInfo source;
	/**
	 * source represents the weibo is broadcast from other weibo
	 */
	private boolean hasSource;
	/**
	 * @return the hasSource
	 */
	public boolean isHasSource() {
		return hasSource;
	}

	/**
	 * @param hasSource the hasSource to set
	 */
	public void setHasSource(boolean hasSource) {
		this.hasSource = hasSource;
	}

	/**
	 * @return the source
	 */
	public TecentWeiboInfo getSource() {
		return source;
	}

	/**
	 * @param source the source to set
	 */
	public void setSource(TecentWeiboInfo source) {
		this.source = source;
	}
	
	private String from;
	/**
	 * @return the from
	 */
	public String getFrom() {
		return from;
	}

	/**
	 * @param from the from to set
	 */
	public void setFrom(String from) {
		this.from = from;
	}
	
	/**
	 * weibo type string's resource id
	 */
	private int typeResId;
	/**
	 * @return the type
	 */
	public int getTypeResId() {
		return typeResId;
	}

	/**
	 * @param type the type to set
	 */
	public void setTypeResId(int type) {
		switch (type) {
		case InfoType.Info_Orig:
			typeResId = R.string.weibo_type_orig;
			break;
		case InfoType.Info_Cast:
			typeResId = R.string.weibo_type_cast;
			break;	
		case InfoType.Info_Reply:
			typeResId = R.string.weibo_type_reply;
			break;
		default:
			typeResId = -1;
			break;
		}
	}
	public static final Parcelable.Creator<TecentWeiboInfo> CREATOR = new Parcelable.Creator<TecentWeiboInfo>() {
		public TecentWeiboInfo createFromParcel(Parcel in) {
			TecentWeiboInfo wb = new TecentWeiboInfo();
			wb.setId(in.readString());
			wb.setUserId(in.readString());
			wb.setUserName(in.readString());
			wb.setUserIcon(in.readString());
			wb.setTime(in.readString());
			wb.setHaveImage(Boolean.parseBoolean(in.readString()));
			ArrayList<String> imgUrlList = new ArrayList<String>();
			in.readStringList(imgUrlList);
			wb.setImageUrlList(imgUrlList);
			wb.setText(in.readString());
			wb.setFrom(in.readString());
			wb.setHasSource(Boolean.parseBoolean(in.readString()));
			if(wb.hasSource){
				wb.setSource(createFromParcel(in));
			}
			wb.setCastCount(in.readString());
			wb.setCommentCount(in.readString());
			return wb;
		}

		public TecentWeiboInfo[] newArray(int size) {
			return new TecentWeiboInfo[size];
		}
	};


	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}
	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(getId());
		dest.writeString(getUserId());
		dest.writeString(getUserName());
		dest.writeString(getUserIcon());
		dest.writeString(getTime());
		if(getHaveImage())
			dest.writeString("true");
		else
			dest.writeString("false");
		dest.writeStringList(getImageUrlList());
		dest.writeString(getText());
		dest.writeString(getFrom());
		if(hasSource){
			dest.writeString("true");
			getSource().writeToParcel(dest, flags);
		}else{
			dest.writeString("false");
		}
		dest.writeString(getCastCount());
		dest.writeString(getCastCount());
	}
}
